<?php

namespace app\api\controller\product;

use app\api\controller\Controller;
use app\api\model\product\ProductBrandRelationModel;
use app\Request;
use app\shop\model\product\BrandModel;

/**
 * 商品分类控制器
 */
class Brand extends Controller
{
    /**
     * 品牌列表
     */
    public function index()
    {
        $list = BrandModel::listAll([], [], 'sort_num desc');
        return $this->renderSuccess('', compact('list'));
    }

    public function product(Request $request)
    {
        $param = $request->param();
        $user = $this->getUser(false);
        if ($user) {
            $list = ProductBrandRelationModel::productListByUser($param, $user);
        } else {
            $list = ProductBrandRelationModel::productList($param);
        }
        return $this->renderSuccess('', compact('list'));
    }

}
